<template>
    <h2>登录页面</h2>
<table>
    <tr>
        <td colspan="2">登录页面</td>
    </tr>
    <tr>
        <td>用户名:</td>
        <td>
            <input type="text" v-model="name">
        </td>
    </tr>
    <tr>
        <td>密码:</td>
        <td>
            <input type="password" v-model="pwd">
        </td>
    </tr>
    <tr>
        <td></td>
        <td>
            <input type="button" value="登录" @click="SaveData">
        </td>
    </tr>
</table>

</template>

<script setup lang="ts">

import {ref} from 'vue'

import axios from 'axios'

import { useRouter} from 'vue-router'

import{useMemberStore} from '../../store/index.ts'

const MemberStore=useMemberStore();




//创建路由函数对应的实例
const router=useRouter();

const name=ref("");
const pwd=ref("");


const SaveData=()=>{


    if(name.value==""){
        alert("用户名不能为空");
        return;
    }
    if(pwd.value==""){
        alert("密码不能为空");
        return;
    }

    axios.get('https://localhost:7153/api/Member/Login/Login',
    {
            params:{
                name:name.value,
                pwd:pwd.value
            }
    }
    )
    .then(res=>{

        console.log(res);
        if(res.data.Code_Id>0){
            alert("登录成功");
            alert("欢迎您，尊敬的："+res.data.Data_info.M_Name);

            MemberStore.MemberName=res.data.Data_info.M_Name;
            MemberStore.$reset();
            alert(MemberStore.MemberName);
           //路由实现页面的跳转
           router.push("/ShowMember");


        }
        else if(res.data.Code_Id==-1){
            alert("账号错误");
        }
        else if(res.data.Code_Id==-2){
            alert("账号密码不匹配");
        }
        else{
            alert("登录失败");
        }
    })
   

}

</script>